import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/auto_makers/perfect_images/license_pic.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:intl/intl.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///企业实名认证
class CompanyRealName extends StatefulWidget {
  @override
  _CompanyRealNameState createState() => _CompanyRealNameState();
}

class _CompanyRealNameState extends State<CompanyRealName> {
  TextEditingController _enterpriseName = TextEditingController(); //企业名称
  bool personInfo = false; //个人信息
  bool enterprise = false; //企业实名认证
  String _establishmentBirth = ""; //成立日期
  String _operatingPeriod = ""; //营业期限
  File iDFront; //身份证正面
  File iDReverse; //身份证反面
  File license; //营业执照
  int role = 2; //用户角色
  List<File> fileList = []; //维修资质图片数组
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
          backgroundColor: Colors.white,
          appBar: AppBar(
            elevation: 0.4,
            centerTitle: true,
            backgroundColor: Colors.white,
            leading: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.pop(context);
              },
              child: Row(
                children: [
                  Container(
                      margin: EdgeInsets.only(left: setWidth(15)),
                      width: setWidth(10),
                      height: setWidth(17),
                      child: Image.asset(
                        "assets/images/return.png",
                        fit: BoxFit.cover,
                      )),
                ],
              ),
            ),
            title: Text(
              "企业实名认证",
              style: TextStyle(color: Color(0xff333333), fontSize: setSp(18)),
            ),
          ),
          body: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(
                      left: setWidth(15),
                      top: setWidth(40),
                      right: setWidth(15)),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        child: Text(
                          "企业实名认证",
                          style: TextStyle(
                              color: YTTheme.theme,
                              fontSize: setSp(15),
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                      SizedBox(
                        height: setWidth(24),
                      ),
                      //身份證照片
                      LicensePic(
                          licenseImg: license, getLicenseImg: getLicenseImg),
                      //企业名称
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "企业名称",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                controller: _enterpriseName,
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                    border: InputBorder.none,
                                    focusedBorder: InputBorder.none,
                                    enabledBorder: InputBorder.none,
                                    hintText: "请输入企业名称",
                                    hintStyle: TextStyle(
                                        color: Color(0xff989898),
                                        fontSize: setSp(15))),
                              ),
                            )),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  margin:
                      EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
                  child: Column(
                    children: [
                      //统一信用代码
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "统一信用代码",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                inputFormatters: [
                                  WhitelistingTextInputFormatter(
                                      RegExp("[0-9.]|[a-zA-Z]")),
                                  //只允许输入数字字母
                                ],
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入统一信用代码",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                      //类型
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "类型",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入类型",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                      //住所
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "住所",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入住所",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                      //法定代表人
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "法定代表人",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入法定代表人",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                      //注册资本
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "注册资本",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入注册资本",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                      //成立日期
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(21), bottom: setWidth(21)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "成立日期",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            GestureDetector(
                              onTap: () {
                                FocusScope.of(context)
                                    .requestFocus(FocusNode());
                                DatePicker.showDatePicker(context,
                                    // 是否展示顶部操作按钮
                                    showTitleActions: true,
                                    // change事件
                                    onChanged: (date) {
                                  print('change $date');
                                },
                                    // 确定事件
                                    onConfirm: (date) {
                                  _establishmentBirth =
                                      DateFormat("yyyy-MM-dd").format(date);
                                  print('confirm $date');
                                },
                                    // 当前时间
                                    currentTime: DateTime.now(),
                                    // 语言
                                    locale: LocaleType.zh);
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  SizedBox(
                                    width: setWidth(3),
                                  ),
                                  Container(
                                    child: Text(
                                      _establishmentBirth != ""
                                          ? _establishmentBirth
                                          : "请输入成立日期",
                                      style: TextStyle(
                                          color: Color(0xff989898),
                                          fontSize: setSp(15)),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      //营业期限
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(21), bottom: setWidth(21)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "营业期限",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            GestureDetector(
                              onTap: () {
                                FocusScope.of(context)
                                    .requestFocus(FocusNode());
                                DatePicker.showDatePicker(context,
                                    // 是否展示顶部操作按钮
                                    showTitleActions: true,
                                    // change事件
                                    onChanged: (date) {
                                  print('change $date');
                                },
                                    // 确定事件
                                    onConfirm: (date) {
                                  _operatingPeriod =
                                      DateFormat("yyyy-MM-dd").format(date);
                                  print('confirm $date');
                                },
                                    // 当前时间
                                    currentTime: DateTime.now(),
                                    // 语言
                                    locale: LocaleType.zh);
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  SizedBox(
                                    width: setWidth(3),
                                  ),
                                  Container(
                                    child: Text(
                                      _operatingPeriod != ""
                                          ? _operatingPeriod
                                          : "请输入营业期限",
                                      style: TextStyle(
                                          color: Color(0xff989898),
                                          fontSize: setSp(15)),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      //营业范围
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                          bottom: BorderSide(
                            color: Color(0xffF0F0F0),
                            width: 0.5,
                          ),
                        )),
                        padding: EdgeInsets.only(
                            top: setWidth(5), bottom: setWidth(5)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(
                              child: Text(
                                "营业范围",
                                style: TextStyle(
                                    color: Color(0xff321212),
                                    fontSize: setSp(15)),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(50),
                            ),
                            Expanded(
                                child: Container(
                              child: TextField(
                                textAlign: TextAlign.end,
                                maxLines: 1,
                                keyboardType: TextInputType.multiline,
                                autofocus: false,
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  focusedBorder: InputBorder.none,
                                  enabledBorder: InputBorder.none,
                                  hintText: "请输入营业范围",
                                  hintStyle: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(16)),
                                ),
                              ),
                            )),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  height: setWidth(80),
                )
              ],
            ),
          ),
          //提交
          bottomSheet: confirmButton(title: "确定", voidCallback: () {
            Navigator.pop(context);
          })),
    );
  }

  //营业执照
  getLicenseImg(File images) {
    setState(() {
      license = images;
    });
  }
}
